from rest_framework import serializers
from goods.models import SPU, Brand, GoodsCategory


class GoodsCategoriesSerializer(serializers.ModelSerializer):
    # 一级分类
    class Meta:
        model = GoodsCategory
        fields = ('id', 'name')


class GoodsBrandsSimpleSerializer(serializers.ModelSerializer):
    # 商品分类
    class Meta:
        model = Brand
        fields = ('id', 'name')


class SpusGoodsSerializer(serializers.ModelSerializer):
    # spu 管理
    category1_id = serializers.IntegerField(label='一级分类id')
    category2_id = serializers.IntegerField(label='二级分类id')
    category3_id = serializers.IntegerField(label='三级分类id')
    brand = serializers.StringRelatedField(label='品牌名称')
    brand_id = serializers.IntegerField(label='品牌名称id')

    class Meta:
        model = SPU
        fields = '__all__'

        # extra_kwargs = {
        #     'sales': {
        #         'read_only': True
        #     },
        #     'comments': {
        #         'read_only': True
        #     }
        # }